<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .box {
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            width: 200px;
            height: 200px;
            border: 1px solid red;
            border-radius: 10px;
            margin-bottom: 20px;
        }

        #fix {
            position: fixed;
            margin-left: 300px;
        }

        #scroll {
            position: fixed;
            margin-left: 400px;
        }

        #toTop {
            position: fixed;
            margin-left: 500px;
        }
    </style>
</head>
<body>
<div>
    <button id="fix" onclick=showLocation()>显示位置</button>
    <button id="scroll" onclick=scrollToPlace()>返回顶部</button>
    <button id="toTop" onclick=toTop()>向下移动一点</button>
</div>
<div>
    <div class="box">1</div>
    <div class="box">2</div>
    <div class="box">3</div>
    <div class="box">4</div>
    <div class="box">5</div>
    <div class="box">6</div>
    <div class="box">7</div>
    <div class="box">8</div>
    <div class="box">9</div>
    <div class="box">10</div>
    <div class="box">11</div>
    <div class="box">12</div>
    <div class="box">13</div>
    <div class="box">14</div>
</div>

<script>
    
    /*
            重要
  */
    
    /*
        返回页面距离上面和左边的距离,有滚动条
        window.pageXoffset/window.scrollX 相等
         window.pageYoffset/window.scrollY 相等
     */
    function showLocation() {

        console.log('pageXOffset', pageXOffset)
        console.log('pageYOffset', pageYOffset)
        console.log('scrollX', scrollX)
        console.log('scrollY', scrollY)
    }

    /*
        scrollTo(x,y)
        scrollBy(x,y)
            -另一种传参方式
               {
                let:100,
                top:100,
                behavior:'auto'  || 'smooth'
               }
            
    */
    function scrollToPlace() {
        // 移动到
        // scrollTo(0, 0);
        scrollTo({
            let: 0,
            top: 0,
            behavior: 'smooth'
        })
    }

    function toTop() {
        let random = Math.floor(Math.random() * 400 + 100)
        // 移动多少距离
        // scrollBy(0,random)
        scrollBy({
            let: 0,
            top: random,
            behavior: 'smooth'
        })
    }


    /*
        scrollBy(x,y)  
        scrollTo(x,y)
     */
</script>
</body>
</html>